package io.renren.modules.pile.controller;

import java.util.Arrays;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.modules.pile.entity.PileEntity;
import io.renren.modules.pile.service.PileService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

@RestController
@RequestMapping("pile/pile")
public class PileController {
    @Autowired
    private PileService pileService;

    @RequestMapping("/list")
    @RequiresPermissions("pile:pile:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pileService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping("/info/{pileNo}")
    @RequiresPermissions("pile:pile:info")
    public R info(@PathVariable("pileNo") Integer pileNo){
		PileEntity pile = pileService.getById(pileNo);
        return R.ok().put("pile", pile);
    }

    @RequestMapping("/save")
    @RequiresPermissions("pile:pile:save")
    public R save(@RequestBody PileEntity pile){
		pileService.save(pile);
        return R.ok();
    }

    @RequestMapping("/update")
    @RequiresPermissions("pile:pile:update")
    public R update(@RequestBody PileEntity pile){
		pileService.updateById(pile);
        return R.ok();
    }

    @RequestMapping("/delete")
    @RequiresPermissions("pile:pile:delete")
    public R delete(@RequestBody Integer[] pileNos){
		pileService.removeByIds(Arrays.asList(pileNos));
        return R.ok();
    }

}
